package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author wjs
 * @version 1.0
 * @date 2021/12/25 0025 下午 4:56
 */

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public List<UserInfo> blackListPageByUserId(Long userId, int page, int size) {

        int i = (page - 1) * 2;

        List<UserInfo> list = userInfoMapper.blackListPageByUserId(userId,i,size);

        return list;
    }

    @Override
    public void deleteBlackList(Long blackUserId, Long userId) {
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getUserId,userId)
                .eq(BlackList::getBlackUserId,blackUserId);
        blackListMapper.delete(lqw);
    }

    @Override
    public Long blackListByUserId(Long userId) {
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getUserId,userId);
        Integer count = blackListMapper.selectCount(lqw);
        return Long.valueOf(count);
    }


}
